<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>用户登录</title>
    <link href="https://cdn.jsdelivr.net/npm/font-awesome@4.7.0/css/font-awesome.min.css" rel="stylesheet">
    <style>
        :root {
            --primary-color: #3B82F6;
            --primary-dark: #2563EB;
            --primary-light: #DBEAFE;
            --text-dark: #1E293B;
            --text-light: #F8FAFC;
            --gray-light: #F1F5F9;
            --gray: #94A3B8;
            --gray-dark: #64748B;
            --danger: #EF4444;
            --success: #10B981;
            --shadow: 0 10px 25px -5px rgba(0, 0, 0, 0.1), 0 8px 10px -6px rgba(0, 0, 0, 0.1);
            --transition: all 0.3s ease;
        }

        * {
            margin: 0;
            padding: 0;
            box-sizing: border-box;
            font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
        }

        body {
            min-height: 100vh;
            display: flex;
            align-items: center;
            justify-content: center;
            background-color: #f8fafc;
            padding: 20px;
        }

        .login-container {
            display: flex;
            width: 100%;
            max-width: 1000px;
            background-color: white;
            border-radius: 16px;
            box-shadow: var(--shadow);
            overflow: hidden;
        }

        /* 图片轮换区域 */
        .image-slider {
            position: relative;
            flex: 1;
            min-height: 600px;
            overflow: hidden;
        }

        .slider-image {
            position: absolute;
            top: 0;
            left: 0;
            width: 100%;
            height: 100%;
            object-fit: cover;
            opacity: 0;
            transition: opacity 1.5s ease-in-out;
        }

        .slider-image.active {
            opacity: 1;
        }

        .image-overlay {
            position: absolute;
            bottom: 0;
            left: 0;
            right: 0;
            padding: 40px;
            background: linear-gradient(transparent, rgba(0, 0, 0, 0.7));
            color: var(--text-light);
        }

        .image-title {
            font-size: 24px;
            font-weight: 600;
            margin-bottom: 10px;
            transform: translateY(20px);
            opacity: 0;
            transition: var(--transition);
        }

        .image-description {
            font-size: 16px;
            opacity: 0.9;
            transform: translateY(20px);
            opacity: 0;
            transition: var(--transition);
            transition-delay: 0.2s;
        }

        .image-slider.active .image-title,
        .image-slider.active .image-description {
            transform: translateY(0);
            opacity: 1;
        }

        .slider-indicators {
            position: absolute;
            bottom: 20px;
            left: 50%;
            transform: translateX(-50%);
            display: flex;
            gap: 8px;
        }

        .indicator {
            width: 10px;
            height: 10px;
            border-radius: 50%;
            background-color: rgba(255, 255, 255, 0.5);
            cursor: pointer;
            transition: var(--transition);
        }

        .indicator.active {
            background-color: white;
            width: 30px;
            border-radius: 5px;
        }

        /* 登录表单区域 */
        .login-form {
            flex: 1;
            padding: 60px;
            display: flex;
            flex-direction: column;
        }

        .login-header {
            margin-bottom: 40px;
        }

        .login-title {
            font-size: 32px;
            font-weight: 700;
            color: var(--text-dark);
            margin-bottom: 10px;
        }

        .login-subtitle {
            color: var(--gray-dark);
            font-size: 16px;
        }

        .form-group {
            margin-bottom: 25px;
            position: relative;
        }

        .form-label {
            display: block;
            margin-bottom: 8px;
            font-weight: 500;
            color: var(--text-dark);
        }

        .form-input {
            width: 100%;
            padding: 14px 16px;
            padding-left: 45px;
            border: 1px solid var(--gray);
            border-radius: 8px;
            font-size: 16px;
            transition: var(--transition);
        }

        .form-input:focus {
            outline: none;
            border-color: var(--primary-color);
            box-shadow: 0 0 0 3px var(--primary-light);
        }

        .form-icon {
            position: absolute;
            left: 16px;
            top: 50%;
            transform: translateY(-50%);
            color: var(--gray-dark);
        }

        .form-hint {
            display: flex;
            justify-content: space-between;
            margin-top: 10px;
            font-size: 14px;
        }

        .remember-me {
            display: flex;
            align-items: center;
            gap: 8px;
            color: var(--gray-dark);
        }

        .forgot-password {
            color: var(--primary-color);
            text-decoration: none;
            transition: var(--transition);
        }

        .forgot-password:hover {
            color: var(--primary-dark);
            text-decoration: underline;
        }

        .btn {
            width: 100%;
            padding: 14px;
            border: none;
            border-radius: 8px;
            font-size: 16px;
            font-weight: 600;
            cursor: pointer;
            transition: var(--transition);
            display: flex;
            align-items: center;
            justify-content: center;
            gap: 8px;
        }

        .btn-primary {
            background-color: var(--primary-color);
            color: white;
        }

        .btn-primary:hover {
            background-color: var(--primary-dark);
            transform: translateY(-2px);
            box-shadow: 0 10px 15px -3px rgba(59, 130, 246, 0.3);
        }

        .btn-primary:active {
            transform: translateY(0);
        }

        .btn-primary:disabled {
            background-color: var(--gray);
            cursor: not-allowed;
            transform: none;
            box-shadow: none;
        }

        .divider {
            display: flex;
            align-items: center;
            gap: 16px;
            margin: 30px 0;
        }

        .divider-line {
            flex: 1;
            height: 1px;
            background-color: var(--gray);
        }

        .divider-text {
            font-size: 14px;
            color: var(--gray-dark);
        }

        .social-login {
            display: flex;
            gap: 16px;
        }

        .social-btn {
            flex: 1;
            padding: 12px;
            border: 1px solid var(--gray);
            background-color: white;
            border-radius: 8px;
            display: flex;
            align-items: center;
            justify-content: center;
            gap: 8px;
            font-weight: 500;
            cursor: pointer;
            transition: var(--transition);
        }

        .social-btn:hover {
            background-color: var(--gray-light);
            border-color: var(--gray-dark);
        }

        .signup-link {
            margin-top: 40px;
            text-align: center;
            color: var(--gray-dark);
        }

        .signup-link a {
            color: var(--primary-color);
            font-weight: 600;
            text-decoration: none;
            transition: var(--transition);
        }

        .signup-link a:hover {
            color: var(--primary-dark);
            text-decoration: underline;
        }

        .message {
            font-size: 14px;
            margin-top: 5px;
            display: none;
            padding: 8px 12px;
            border-radius: 4px;
        }

        .error-message {
            color: var(--danger);
            background-color: #fee2e2;
        }

        .error-message.show {
            display: block;
        }

        .success-message {
            color: var(--success);
            background-color: #dcfce7;
        }

        .success-message.show {
            display: block;
        }

        .loading {
            width: 16px;
            height: 16px;
            border: 2px solid rgba(255, 255, 255, 0.3);
            border-radius: 50%;
            border-top-color: white;
            animation: spin 1s ease-in-out infinite;
        }

        @keyframes spin {
            to { transform: rotate(360deg); }
        }

        /* 响应式设计 */
        @media (max-width: 768px) {
            .login-container {
                flex-direction: column;
            }

            .image-slider {
                min-height: 250px;
            }

            .image-overlay {
                padding: 20px;
            }

            .image-title {
                font-size: 20px;
            }

            .image-description {
                font-size: 14px;
            }

            .login-form {
                padding: 30px 20px;
            }

            .login-title {
                font-size: 28px;
            }

            .social-login {
                flex-direction: column;
            }
        }
    </style>
</head>
<body>
    <div class="login-container">
        <!-- 动态图片轮换区域 -->
        <div class="image-slider">
            <img src="https://picsum.photos/seed/work1/800/1000" alt="工作场景" class="slider-image active" data-title="高效工作空间" data-description="打造专属于你的高效工作环境，提升工作效率">
            <img src="https://picsum.photos/seed/secure1/800/1000" alt="安全保障" class="slider-image" data-title="安全保障" data-description="多重安全验证，保障你的账户信息安全">
            <img src="https://picsum.photos/seed/collab1/800/1000" alt="团队协作" class="slider-image" data-title="团队协作" data-description="无缝协作，轻松分享，提升团队生产力">
            
            <div class="image-overlay">
                <h3 class="image-title">高效工作空间</h3>
                <p class="image-description">打造专属于你的高效工作环境，提升工作效率</p>
            </div>
            
            <div class="slider-indicators">
                <div class="indicator active" data-index="0"></div>
                <div class="indicator" data-index="1"></div>
                <div class="indicator" data-index="2"></div>
            </div>
        </div>

        <!-- 登录表单区域 -->
        <div class="login-form">
            <div class="login-header">
                <h1 class="login-title">欢迎回来</h1>
                <p class="login-subtitle">请输入您的账号信息登录系统</p>
            </div>

            <form id="loginForm">
                <div class="form-group">
                    <label for="username" class="form-label">用户名</label>
                    <i class="fa fa-user form-icon"></i>
                    <input type="text" id="username" class="form-input" placeholder="请输入用户名" required>
                    <div class="message error-message" id="usernameError"></div>
                </div>

                <div class="form-group">
                    <label for="password" class="form-label">密码</label>
                    <i class="fa fa-lock form-icon"></i>
                    <input type="password" id="password" class="form-input" placeholder="请输入密码" required>
                    <div class="message error-message" id="passwordError"></div>
                </div>

                <div class="form-hint">
                    <label class="remember-me">
                        <input type="checkbox" id="rememberMe"> 记住我
                    </label>
                    <a href="#" class="forgot-password">忘记密码?</a>
                </div>

                <button type="submit" class="btn btn-primary" id="loginBtn">
                    <i class="fa fa-sign-in"></i>
                    <span>登录</span>
                    <div class="loading" style="display: none;"></div>
                </button>

                <div class="message error-message" id="loginError"></div>
                <div class="message success-message" id="loginSuccess"></div>

                <div class="divider">
                    <div class="divider-line"></div>
                    <div class="divider-text">或使用以下方式登录</div>
                    <div class="divider-line"></div>
                </div>

                <div class="social-login">
                    <button type="button" class="social-btn">
                        <i class="fa fa-weixin"></i> 微信
                    </button>
                    <button type="button" class="social-btn">
                        <i class="fa fa-qq"></i> QQ
                    </button>
                </div>
            </form>

            <p class="signup-link">
                还没有账号? <a href="#">立即注册</a>
            </p>
        </div>
    </div>

    <script>
        // 图片轮换功能
        document.addEventListener('DOMContentLoaded', function() {
            const images = document.querySelectorAll('.slider-image');
            const indicators = document.querySelectorAll('.indicator');
            const imageTitle = document.querySelector('.image-title');
            const imageDescription = document.querySelector('.image-description');
            const imageSlider = document.querySelector('.image-slider');
            let currentIndex = 0;
            let slideInterval;

            // 初始化轮播
            function initSlider() {
                startSlideInterval();
                
                // 为指示器添加点击事件
                indicators.forEach((indicator, index) => {
                    indicator.addEventListener('click', () => {
                        goToSlide(index);
                        resetSlideInterval();
                    });
                });
            }

            // 切换到指定幻灯片
            function goToSlide(index) {
                // 移除所有活动状态
                images.forEach(img => img.classList.remove('active'));
                indicators.forEach(ind => ind.classList.remove('active'));
                
                // 添加当前活动状态
                images[index].classList.add('active');
                indicators[index].classList.add('active');
                
                // 更新标题和描述
                imageTitle.textContent = images[index].dataset.title;
                imageDescription.textContent = images[index].dataset.description;
                
                // 添加动画效果
                imageSlider.classList.remove('active');
                setTimeout(() => {
                    imageSlider.classList.add('active');
                }, 50);
                
                currentIndex = index;
            }

            // 下一张幻灯片
            function nextSlide() {
                let nextIndex = currentIndex + 1;
                if (nextIndex >= images.length) {
                    nextIndex = 0;
                }
                goToSlide(nextIndex);
            }

            // 开始自动轮播
            function startSlideInterval() {
                slideInterval = setInterval(nextSlide, 5000); // 每5秒切换一次
            }

            // 重置轮播计时器
            function resetSlideInterval() {
                clearInterval(slideInterval);
                startSlideInterval();
            }

            // 登录功能实现
            const loginForm = document.getElementById('loginForm');
            const username = document.getElementById('username');
            const password = document.getElementById('password');
            const rememberMe = document.getElementById('rememberMe');
            const loginBtn = document.getElementById('loginBtn');
            const loginError = document.getElementById('loginError');
            const loginSuccess = document.getElementById('loginSuccess');
            const usernameError = document.getElementById('usernameError');
            const passwordError = document.getElementById('passwordError');
            const loadingIndicator = loginBtn.querySelector('.loading');
            const loginText = loginBtn.querySelector('span');

            // 清除所有消息
            function clearAllMessages() {
                [loginError, loginSuccess, usernameError, passwordError].forEach(el => {
                    el.classList.remove('show');
                });
            }

            // 显示加载状态
            function showLoading() {
                loginBtn.disabled = true;
                loadingIndicator.style.display = 'block';
                loginText.style.display = 'none';
            }

            // 隐藏加载状态
            function hideLoading() {
                loginBtn.disabled = false;
                loadingIndicator.style.display = 'none';
                loginText.style.display = 'inline';
            }

            // 表单验证
            function validateForm() {
                let isValid = true;
                clearAllMessages();

                // 验证用户名
                if (!username.value.trim()) {
                    usernameError.textContent = '用户名不能为空';
                    usernameError.classList.add('show');
                    isValid = false;
                }

                // 验证密码
                if (password.value.length < 6) {
                    passwordError.textContent = '密码长度不能少于6位';
                    passwordError.classList.add('show');
                    isValid = false;
                }

                return isValid;
            }

            // 登录API调用
            async function login(username, password, remember) {
                try {
                    // 显示加载状态
                    showLoading();
                    
                    // 调用登录API
                    const response = await fetch('/v1/user/login', {
                        method: 'POST',
                        headers: {
                            'Content-Type': 'application/json',
                        },
                        body: JSON.stringify({
                            username: username,
                            password: password
                        }),
                        credentials: remember ? 'include' : 'same-origin'
                    });

                    // 解析响应
                    const result = await response.json();
                    
                    // 隐藏加载状态
                    hideLoading();
                    
                    return result;
                } catch (error) {
                    // 处理网络错误
                    hideLoading();
                    return {
                        success: false,
                        message: '网络错误，请稍后重试'
                    };
                }
            }

            // 表单提交事件
            loginForm.addEventListener('submit', async function(e) {
                e.preventDefault();
                
                // 客户端表单验证
                if (!validateForm()) {
                    return;
                }

                // 获取表单数据
                const usernameVal = username.value.trim();
                const passwordVal = password.value;
                const rememberVal = rememberMe.checked;

                // 调用登录API
                const result = await login(usernameVal, passwordVal, rememberVal);

                // 处理登录结果
                if (result.success) {
                    // 登录成功
                    loginSuccess.textContent = result.message || '登录成功，正在跳转...';
                    loginSuccess.classList.add('show');
                    
                    // 存储用户信息到localStorage或sessionStorage
                    if (rememberVal) {
                        localStorage.setItem('userInfo', JSON.stringify(result.data || {}));
                    } else {
                        sessionStorage.setItem('userInfo', JSON.stringify(result.data || {}));
                    }
                    
                    // 登录成功后跳转
                    setTimeout(() => {
                        window.location.href = '/dashboard'; // 替换为实际的首页URL
                    }, 1500);
                } else {
                    // 登录失败
                    loginError.textContent = result.message || '登录失败，请检查用户名和密码';
                    loginError.classList.add('show');
                }
            });

            // 输入时实时验证
            username.addEventListener('input', function() {
                if (username.value.trim()) {
                    usernameError.classList.remove('show');
                }
            });

            password.addEventListener('input', function() {
                if (password.value.length >= 6) {
                    passwordError.classList.remove('show');
                }
            });

            // 初始化轮播
            initSlider();
        });
    </script>
</body>
</html>
    